var base = require('/base_info.js');
var utils = require('/utils/index.js');
Page({
  data: {
    items: [
      { value: '天气因素无法抵达酒店', id: 0 },
      { value: '行程有变需取消订单', id: 1 },
      { value: '下单错误需重新预订', id: 2 },
      { value: '其他', id: 3 }
    ],
    checkedIndex: 0,
    order_id: 0,
    refund_explain: ''
  },
  radioChange: function(e) {
    this.setData({
      checkedIndex: e.detail.value
    })
  },
  insInput (e) {
    this.setData({
      refund_explain: e.detail.value
    });
  },
  refund () {
    let that = this;
    console.log({
      order_id: that.data.order_id,
      refund_reason: that.data.items[that.data.checkedIndex * 1].value,
      refund_explain: that.data.refund_explain
    })
    my.confirm({
      title: '',
      content: '订单一旦申请将需要重新预订,是否确定申请退款？',
      confirmButtonText: '是',
      cancelButtonText: '否',
      success: (result) => {
        if (result.confirm) {
          my.showLoading();
          utils.getData('SingleApplyRefund', {
            order_id: that.data.order_id,
            refund_reason: that.data.items[that.data.checkedIndex * 1].value,
            refund_explain: that.data.refund_explain
          }, (res) => {
            my.hideLoading();
            if (res.data.errno == 1) {
              my.alert({
                title: `已成功申请退款`,
                success: () => {
                  my.navigateBack({});
                }
              });
              return false;
            }
            my.alert({
              title: `${res.data.message}`,
            });
          }, (err) => {
            my.hideLoading();
            my.alert({
              title: `网络错误，请稍后再试`,
            });
          });
        }
      },
    });
  },
  onLoad(query) {
    console.log(query);
    this.setData({
      order_id: query.id
    });
  },
  onReady() {
    // 页面加载完成
  },
  onShow() {
    // 页面显示
  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
  },
  onTitleClick() {
    // 标题被点击
  },
  onPullDownRefresh() {
    // 页面被下拉
  },
  onReachBottom() {
    // 页面被拉到底部
  },
  onShareAppMessage() {
    // 返回自定义分享信息
    return {
      title: my.getStorageSync({
        key: 'hotel_name', // 缓存数据的key
      }).data,
      desc: my.getStorageSync({
        key: 'my_app_description', // 缓存数据的key
      }).data,
      path: 'pages/index/index?share=true',
      success: function (e) {
        console.log(e);
      }
    };
  },
});
